package com.goldgov.code.template.impl;

import java.util.Map;

import com.goldgov.code.meta.FieldInfo;
import com.goldgov.code.meta.ModuleInfo;
import com.goldgov.code.template.Group;
import com.goldgov.code.template.Layout;
import com.goldgov.code.template.commons.impl.tree.TreePlugin;
import com.goldgov.code.template.point.PointMapping;

public class PageLayout implements Layout{
	
	public static final String PACKAGE_NAME = "page";

	private String templatePath = PACKAGE_NAME;
	
	@Override
	public String packageName() {
		return PACKAGE_NAME;
	}

	@Override
	public String templatePath() {
		return templatePath;
	}

	@Override
	public Class<?>[] dependOn() {
		return new Class<?>[]{WebLayout.class};
	}
	
	public void setTemplatePath(String templatePath) {
		this.templatePath = templatePath;
	}

	@Override
	public PointMapping codePoint(String packageName, ModuleInfo moduleInfo, Group group,Map<String,Object> paramMap) {
		return null;
	}

	@Override
	public void init(ModuleInfo moduleInfo) {
		FieldInfo[] fields = moduleInfo.getFields();
		boolean hasParentField = false;
		boolean hasTreePathField = false;
		for (FieldInfo fieldInfo : fields) {
			if(fieldInfo.getField().equals(TreePlugin.FIELD_NAME_PARENT_ID)) {
				hasParentField = true;
			}else if(fieldInfo.getField().equals(TreePlugin.FIELD_NAME_TREE_PATH)){
				hasTreePathField = true;
			}
		}
		if(hasParentField && hasTreePathField) {
			templatePath = templatePath + "-tree";
		}
	}

}
